/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Form = require("form");
	var aw = require("ajaxwrapper");
	var store =require("store");
	var activeUser = store.get("user");
	var enmu = require("enums");
	
    var instance = {
        initComponent: function (params,widget) {
        	var form = new Form({
        		parentNode: ".J-form",
        		show: false,
        		saveaction: function(){
        			var data = form.getData();
        			aw.saveOrUpdate("api/organizationsettlement/save",data,function(data){
        				widget.get("grid").refresh();
        				widget.show([".J-grid"]).hide([".J-form"]);
						widget.get("subnav").hide(["return"]).show(["add","startDate"]);
        			});
        		},
        		cancelaction: function(){
        			widget.show([".J-grid"]).hide([".J-form"]);
        			widget.get("subnav").hide(["return"]).show(["add","startDate"]);
        			widget.get("grid").refresh();
        		},
        		model: {
        			id: "receivepay",
        			layout:"2_1",
        			items: [{
        				name:"paymentType",
						label:"款项类型",
						type:"select",
						validate:["required"],
						options:enmu["com.eling.elcms.travel.model.OrganizationSettlement.PaymentType"],
			            events: {
			        	   "change": function(e){
			        		   var form = widget.get("form");
			        		   if(form.getValue("paymentType") == "Prepaid"){
			        			   form.setLabel("payer","收款单位");
			        			   form.setLabel("payee","付款单位");
			        		   }else if(form.getValue("paymentType") == "Advance"){
			        			   form.setLabel("payer","付款单位");
			        			   form.setLabel("payee","收款单位");
			        		   }
			        	   }
			           }
        			},{
        				name:"content",
						label:"款项内容",
						validate:["required"],
        			},{
        				name:"payer",
						label:"付款单位",
						type: "select",
						validate:["required"],
						keyField: "pkAllianceOrg",
				        valueField: "name",
				        url: "api/allianceorg/query",
				        params: function() {
				        	 return {
				        		 fetchProperties: "pkAllianceOrg,name"
				                };
				            }
        			},{
        				name:"payee",
						label:"收款单位",
						validate:["required"],
						type: "select",
						keyField: "pkAllianceOrg",
				        valueField: "name",
				        url: "api/allianceorg/query",
				        params: function() {
				        	 return {
				        		 fetchProperties: "pkAllianceOrg,name"
				                };
				            },
				       //defaultValue:activeUser.organization.name  
        			},{
        				name:"expectedAmount",
						label:"款项金额",
						validate:["required"],
        			},{
        				name:"paymentMethod",
						label:"收款方式",
						type:"select",
						validate:["required"],
						options:enmu["com.eling.elcms.travel.model.OrganizationSettlement.PaymentMethod"],
        			},{
        				name:"isInvoice",
						label:"是否开票",
						type:"select",
						options: [{
			                key: "true",
			                value: "是"
			            }, {
			                key: "false",
			                value: "否"
			            }],
			           defaultValue:true,
        			},{
        				name:"invoiceDate",
						label:"开票日期",
						type:"date",
						mode:"YYYY-MM-DD",
						//defaultValue:new Date().getTime(),
						//defaultValue:moment().format("YYYY.MM.DD"),
        			},{
        				name:"payDate",
						label:"收款日期",
						type:"date",
						mode:"YYYY-MM-DD",
						defaultValue:moment().format("YYYY.MM.DD"),
        			},{
        				name:"operator",
						label:"经办人",
						defaultValue:activeUser.name,
        			},{
        				name:"description",
						label:"备注",
						type: "textarea",
                        "break": true,
        			},{
        				name:"pkOrganizationSettlement",
						type:"hidden"
        			},{
        				name:"version",
						type:"hidden",
						defaultValue:"0"
        			}]
        		}
        	});
        	widget.set("form", form);
        }
    };
    module.exports = instance;
});
